<template>
  <div class="businessUnit">
    <div class="table">
      <el-table :data="tableData" :span-method="objectMethod" border :header-cell-style="headerClass" v-loading="tableLoading">
        <el-table-column label="" prop="VERTICAL_INDEX_NAME" align="center"></el-table-column>
        <el-table-column label="收入指标" prop="CLASS1" align="center">
          <el-table-column label="收入指标" prop="CLASS1" align="center"></el-table-column>
          <el-table-column label="收入指标" prop="HORIZON_INDEX_NAME" align="center"></el-table-column>
        </el-table-column>
        <el-table-column v-for="(item,index) in header" :key="index" :label="item" :prop="item" align="center"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import $barCodeApi from "@/api/barCode/index";
export default {
  name: "businessUnit",
  components: {

  },
  props: {
    form: {
      type: Object,
      default: {}
    }
  },
  data () {
    return {
      tableLoading: false,
      tableData: [],
      header:[],
      spanArr1: [],
      spanArr2: []
    };
  },
  computed: {},
  created () { },
  mounted () { },
  methods: {
    headerClass ({ rowIndex }) {
      if (rowIndex === 1) {
        return { display: 'none' }
      }
      return 'background:#0070C0;color:#FFFF'
    },
    objectMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (this.spanArr1[rowIndex]) {
          return {
            rowspan: this.spanArr1[rowIndex],
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
      if (columnIndex === 1) {
        if (this.spanArr2[rowIndex]) {
          return {
            rowspan: this.spanArr2[rowIndex],
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    // 获取码号收入整体趋势
    getList () {
      this.tableLoading = true;
      let obj = Object.assign({}, this.form);
      obj.indexCode = 'YS10000'
      $barCodeApi.getBusinessIncome({ ...obj }, res => {
        if (res.code == 0) {
          this.tableLoading = false;
          this.header = res.content.area
          this.tableData = res.content.data;
          let contactDot = 0;
          let spanArr1 = [];
          let contactDot1 = 0;
          let spanArr2 = [];
          this.tableData.forEach((item, index) => {
            if (index === 0) {
              spanArr1.push(1);
              spanArr2.push(1);
            } else {
              if (
                item.VERTICAL_INDEX_NAME === this.tableData[index - 1].VERTICAL_INDEX_NAME
              ) {
                spanArr1[contactDot] += 1;
                spanArr1.push(0);
              } else {
                contactDot = index;
                spanArr1.push(1);
              }
              if (
                item.CLASS1 === this.tableData[index - 1].CLASS1
              ) {
                spanArr2[contactDot1] += 1;
                spanArr2.push(0);
              } else {
                contactDot1 = index;
                spanArr2.push(1);
              }
            }
          });
          this.spanArr1 = spanArr1;
          this.spanArr2 = spanArr2;
        }
      });
    }
  }
};
</script>

<style scoped></style>
